package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
import com.jme3.light.DirectionalLight;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.shadow.PssmShadowRenderer;
import com.jme3.system.AppSettings;
import mygame.objects.Font;

/**
 * Game class. It's a singleton.
 * @author Matthias
 */
public class Game extends SimpleApplication {


	private static final Controls controls = new Controls();
	private AudioManager audio;
	private static Game instance;

	public static Game getInstance() {
		if (instance == null) {
			instance = new Game();
		}
		return instance;
	}

	private Game() {

		// setup game settings automatically here
		showSettings = false;

		// like this
		settings = new AppSettings(true);
		// 4xAA
		settings.setSamples(4);
		// resolution
		settings.setResolution(1024, 786);
		// window title
		settings.setTitle("NaughtyTeks Vextor");
		// gamepad support
		settings.setUseJoysticks(true);
		
		// use those settings
		setSettings(settings);

		// start the application
		start();
	}

	/**
	 * Initialize the application
	 */
	public void simpleInitApp() {



		// eventually, this kind of code might need to go in a state class

		// TODO: ITS NOT WORK RITHG NOW OMG

		Vector3f lightDirection = new Vector3f(-1, -1, -1).normalizeLocal();

//		BasicShadowRenderer shadowRenderer = new BasicShadowRenderer(
//						assetManager, 256);
//		shadowRenderer.setDirection(lightDirection);
//		viewPort.addProcessor(shadowRenderer);

		rootNode.setShadowMode(ShadowMode.Off);
		PssmShadowRenderer newShadow = new PssmShadowRenderer(assetManager, 1024, 4);
		newShadow.setCompareMode(PssmShadowRenderer.CompareMode.Hardware);
		newShadow.setFilterMode(PssmShadowRenderer.FilterMode.Bilinear);
		newShadow.setDirection(lightDirection);
		viewPort.addProcessor(newShadow);

		// starting position for camera
		cam.setLocation(new Vector3f(2, 5, 2));
		cam.lookAt(Vector3f.UNIT_X, Vector3f.ZERO);

		// a first light
		DirectionalLight sun = new DirectionalLight();
		sun.setDirection(lightDirection);
		rootNode.addLight(sun);

		// Dummy Vextor Font object
		Font font = new Font(new Vector3f());

		// Initialize audio system
		audio = new AudioManager();
		audio.initAudio();

		

		// initialize this games controls
		controls.initKeyMappings();
	}
}
